home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / Cinema - PTGate.ifs < prev    next >
Text File  |  2005-05-24  |  6KB  |  192 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=O Guardiπo (<link>bruno_mga@hotmail.com</link>)
  8. Title=Cinema - PTGate
  9. Description=Movie importation script for :: Cinema - PTGate ::
  10. Site=www.cinema.ptgate.pt
  11. Language=PT
  12. Version=1.7 (24 Maio 2005)
  13. Requires=3.5.0
  14. Comments=Caso detectem erros coloquem-nos no meu site: <link>www.guardiao.pt.vu</link> ou enviem para o email: bruno_mga@hotmail.com
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program PTGate;
  23. uses
  24.   StringUtils1;
  25. var
  26.   MovieName,MovieURL: string;
  27. function HTMLRemove(Value: String): String;
  28. begin
  29.   HTMLDecode(Value);
  30.   HTMLRemoveTags(Value);
  31.   Value := Trim(Value);
  32.   result := Value;
  33. end;
  34.  
  35. procedure AnalyzeFilmPage(Address: String);
  36. var
  37.   Page : TStringList;
  38.   LineNr, BeginPos, EndPos: Integer;
  39.   Line, Value, url_imdb, nome_orig, nome_trad, ano, pais, genero:string;
  40.   interpretes, descricao,capa,realizac:string;
  41. begin
  42.   Page := TStringList.Create;
  43.   Address:='http://cinema.ptgate.pt/filme.php?code='+Address;
  44.   Page.Text := GetPage(Address);
  45.   SetField(fieldURL, Address);
  46.  
  47.   LineNr := FindLine('</b><br><b class=subtitle>', Page, 0);
  48.   if LineNr<>-1 then
  49.   begin
  50.     Value := Page.GetString(LineNr);
  51.     BeginPos:= pos('<b class=title>',value)+15;
  52.     EndPos := pos('</b><br>', value)+8;
  53.     nome_orig:=copy(value,BeginPos,EndPos-BeginPos);
  54.  
  55.     if pos(', The</b>',nome_orig) <>0 then  //colocar "the" no inicio
  56.     begin
  57.       url_imdb:=HTMLRemove(nome_orig);
  58.       nome_orig:= StringReplace(nome_orig, ', The</b><br>', '');
  59.       nome_orig:=HTMLRemove(nome_orig);
  60.       nome_orig:='The '+Copy(nome_orig,1,length(nome_orig));
  61.     end;
  62.     nome_orig:=HTMLRemove(nome_orig);
  63.     SetField(fieldOriginalTitle, nome_orig);
  64.   end;
  65.  
  66.   BeginPos := pos('<b class=subtitle>', value)+18;
  67.   value:= Copy(value,BeginPos,length(value));
  68.   EndPos := pos('</b>',value);
  69.   nome_trad:=Copy(value,1,EndPos);
  70.   nome_trad:=HTMLRemove(nome_trad);
  71.   SetField(fieldTranslatedTitle, nome_trad);
  72.   value:=Copy(value,EndPos,length(value));
  73.  
  74.   BeginPos := pos('<br><br><b>', value)+22;
  75.   value:= Copy(value,BeginPos,length(value));
  76.   EndPos := pos('<br><br><b>',value);
  77.   ano:=Copy(value,1,EndPos);
  78.   ano:=HTMLRemove(ano);
  79.   SetField(fieldYear, ano);
  80.   value:=Copy(value,EndPos,length(value));
  81.  
  82.   BeginPos := pos('<br><b>paφs</b><br>', value)+19;
  83.   value:= Copy(value,BeginPos,length(value));
  84.   EndPos := pos('<br><br><b>',value);
  85.   pais:=Copy(value,1,EndPos);
  86.   pais:=HTMLRemove(pais);
  87.   SetField(fieldCountry, pais);
  88.   value:=Copy(value,EndPos,length(value));
  89.  
  90.   BeginPos := pos('<br><b>gΘnero</b><br>', value)+21;
  91.   value:= Copy(value,BeginPos,length(value));
  92.   EndPos := pos('<br><br><b>',value);
  93.   genero:=Copy(value,1,EndPos);
  94.   genero:=HTMLRemove(genero);
  95.   SetField(fieldCategory, genero);
  96.   value:=Copy(value,EndPos,length(value));
  97.  
  98.   BeginPos := pos('<br><br><b>realizaτπo</b><br>', value)+29;
  99.   value:= Copy(value,BeginPos,length(value));
  100.   EndPos := pos('<br><br><b>',value);
  101.   realizac:=Copy(value,1,EndPos);
  102.   realizac:=StringReplace(realizac,'<br>',',');
  103.   realizac:=HTMLRemove(realizac);
  104.   SetField(fieldDirector, realizac);
  105.   value:=Copy(value,EndPos,length(value));
  106.  
  107.   BeginPos := pos('<br><br><b>intΘrpretes</b><br>', value)+30;
  108.   value:= Copy(value,BeginPos,length(value));
  109.   EndPos := pos('<br><br><b>',value);
  110.   interpretes:=Copy(value,1,EndPos);
  111.   interpretes:= StringReplace(interpretes, '<br>', ', ');
  112.   interpretes:=HTMLRemove(interpretes);
  113.   SetField(fieldActors, interpretes);
  114.   value:=Copy(value,EndPos,length(value));
  115.  
  116.   BeginPos := pos('<br><br><b>sinopse</b><br>', value)+26;
  117.   if BeginPos<>26 then
  118.   begin
  119.     value:= Copy(value,BeginPos,length(value));
  120.     EndPos := pos('<br><br>',value);
  121.     if EndPos=0 then
  122.       EndPos:=length(value);
  123.     descricao:=Copy(value,1,EndPos);
  124.     descricao:=HTMLRemove(descricao);
  125.     descricao:=StringReplace(descricao,'    ','');
  126.     repeat
  127.       if copy(descricao,length(descricao),1)=' ' then
  128.         descricao:=Copy(descricao,0,length(descricao)-1)
  129.       else
  130.         break
  131.     until (descricao='');
  132.     SetField(fieldDescription, descricao);
  133.   end;
  134.  
  135.   LineNr := FindLine('width=100 height=150>', Page, 0);
  136.   Value := Page.GetString(LineNr);
  137.   BeginPos:=pos('<img src=',value)+10;
  138.   EndPos:=pos(' width=100 height=150>',value)-1;
  139.   value:=Copy(value,BeginPos,EndPos-BeginPos);
  140.   value:='http://cinema.ptgate.pt/'+value;
  141.   GetPicture(Value);
  142. end;
  143.  
  144. procedure AnalyzePage(Address,param: string);
  145. var
  146.   Page: TStringList;
  147.   LineNr, StartPos, EndPos: Integer;
  148.   Line: string;
  149.   x:integer;
  150.   MovieAddress, findMovieName,linedown : string;
  151.   guardar,url, nome_filme:string;
  152. begin
  153.   PickTreeClear;
  154.   Page := TStringList.Create;
  155.   Page.Text := PostPage(Address,param);
  156.  
  157.   if (pos('Nπo foram encontrados filmes que satisfaτam o seu critΘrio.', Page.Text)=0) then
  158.   begin
  159.   StartPos:=Pos('!-- DISPLAY RESULTS -->',Page.Text);
  160.   Page.Text:=Copy(Page.Text,StartPos,length(Page.Text));
  161.       LineNr := FindLine('filme.php?code=', Page, LineNr);
  162.       Line := Page.GetString(LineNr);
  163.     repeat
  164.         StartPos := pos('filme.php?code=', Line)+15;
  165.         if StartPos=15 then break;
  166.  
  167.         guardar:=Copy(line,StartPos+1,length(line));
  168.         line:=Copy(line,StartPos,length(line));
  169.         StartPos := pos('>',line)+1;
  170.         url:=(copy(line,1,StartPos-3));
  171.         EndPos := pos('</a>',line)-1;
  172.         line := copy(Line, StartPos, EndPos - StartPos+1);
  173.           nome_filme:=line;
  174.         PickTreeAdd(nome_filme, url);
  175.         line:=guardar;
  176.     until (nome_filme='');
  177.  
  178.     if PickTreeExec(Address) then
  179.       AnalyzeFilmPage(Address);
  180.     Page.Free;
  181.   end
  182.   else
  183.   showmessage('O filme nπo foi encontrado')
  184. end;
  185. begin
  186.   PickListClear;
  187.   MovieName := GetField(fieldOriginalTitle);
  188.   if Input('Importar do cinema.ptgate.pt', 'Escreva o nome do filme:', MovieName) then
  189.   AnalyzePage('http://cinema.ptgate.pt/pesquisa-filme.php',UrlEncode('titulo='+MovieName));
  190. end.
  191.  
  192.